import type { BaseEnum } from "@/enums/base";

/**
 * 工作状态枚举
 * 用于标识工作在流程中的状态
 */
export const WorkStatus = {
  /**
   * 无状态
   */
  None: {
    code: "None",
    name: "无状态",
    index: 0,
    description: "初始状态，未开始任何流程"
  },

  /**
   * 创建未确认
   */
  CreateUnconfirmed: {
    code: "CreateUnconfirmed",
    name: "创建未确认",
    index: 1,
    description: "工作已创建但未确认"
  },

  /**
   * 已确认可报名
   */
  ConfirmedCanApply: {
    code: "ConfirmedCanApply",
    name: "已确认可报名",
    index: 2,
    description: "工作已确认，可以开始报名"
  },

  /**
   * 报名结束
   */
  ApplyEnd: {
    code: "ApplyEnd",
    name: "报名结束",
    index: 3,
    description: "报名阶段已结束"
  },

  /**
   * 已结束
   */
  Terminate: {
    code: "Terminate",
    name: "已结束",
    index: 4,
    description: "工作已完全结束"
  },
} as const;

/**
 * 根据code获取枚举
 * @param code
 * @returns 枚举值或null
 */
export function matchCode(code: string) {
  return (
    Object.values(WorkStatus).find((item) => item.code === code) || null
  );
}

/**
 * 根据index获取枚举
 * @param index
 * @returns 枚举值或null
 */
export function matchIndex(index: number) {
  return (
    Object.values(WorkStatus).find((item) => item.index === index) || null
  );
}

/**
 * 获取所有工作状态选项
 * @returns 工作状态数组
 */
export function getWorkStatusOptions() {
  return Object.values(WorkStatus);
}

/**
 * 判断是否为可报名状态
 * @param status 工作状态枚举值
 * @returns boolean
 */
export function isCanApplyStatus(status: typeof WorkStatus[keyof typeof WorkStatus]): boolean {
  return status.code === WorkStatus.ConfirmedCanApply.code;
}

/**
 * 判断是否为进行中状态（可报名或报名结束但未终止）
 * @param status 工作状态枚举值
 * @returns boolean
 */
export function isActiveStatus(status: typeof WorkStatus[keyof typeof WorkStatus]): boolean {
  const activeCodes: string[] = [
    WorkStatus.ConfirmedCanApply.code,
    WorkStatus.ApplyEnd.code
  ];
  return activeCodes.includes(status.code);
}

/**
 * 判断是否为已结束状态
 * @param status 工作状态枚举值
 * @returns boolean
 */
export function isTerminatedStatus(status: typeof WorkStatus[keyof typeof WorkStatus]): boolean {
  return status.code === WorkStatus.Terminate.code;
}

/**
 * 获取状态的颜色类型（用于UI展示）
 * @param status 工作状态枚举值
 * @returns Element Plus 的 tag 类型
 */
export function getWorkStatusType(status: typeof WorkStatus[keyof typeof WorkStatus]): 'info' | 'warning' | 'success' | 'danger' {
  switch (status.code) {
    case WorkStatus.None.code:
      return 'info';
    case WorkStatus.CreateUnconfirmed.code:
      return 'warning';
    case WorkStatus.ConfirmedCanApply.code:
      return 'success';
    case WorkStatus.ApplyEnd.code:
      return 'warning';
    case WorkStatus.Terminate.code:
      return 'danger';
    default:
      return 'info';
  }
} 